from django.db import models

# Create your models here.
class CityNumber(models.Model):
    city_number = models.CharField('城市编号', max_length=12, primary_key=True, db_index=True)
    city_name = models.CharField('城市名', max_length=50, db_index=True)

    def __str__(self):
        return self.city_name

    class Meta:
        unique_together = ['city_number']
        verbose_name = verbose_name_plural = '城市编号'


class WeatherLive(models.Model):
    temp = models.SmallIntegerField('当前温度', null=True, blank=True)
    temp_highest = models.SmallIntegerField('最高温', null=True, blank=True)
    temp_lowest = models.SmallIntegerField('最低温', null=True, blank=True)
    temp_unit = models.CharField('温度单位', max_length=4, default='℃')
    wd = models.CharField('风向', max_length=8, null=True, blank=True)
    wind_level = models.PositiveSmallIntegerField('风级', null=True, blank=True)
    wind_speed = models.CharField('风速', max_length=16, null=True, blank=True)
    rh = models.CharField('相对湿度', max_length=4, null=True, blank=True)
    weather = models.CharField('天气', max_length=10, null=True, blank=True)
    pm25 = models.FloatField('PM25', null=True, blank=True)
    updated = models.TimeField('实况', null=True, blank=True)
    rain = models.FloatField('降雨量', null=True, blank=True)
    limit = models.CharField('限行', max_length=16, null=True, blank=True)
    refresh = models.DateTimeField('数据刷新时间', auto_now=True)
    city_number = models.ForeignKey('weather.CityNumber', on_delete=models.CASCADE)

    def __str__(self):
        return '%s 天气实况' % self.city_number

    class Meta:
        verbose_name = verbose_name_plural = '城市天气实况'